package main

import (
	"net/http"
	"log"
	"strings"
	"os"
	"fmt"
)

func logger(req *http.Request, code int)  {
	remoteAddr := strings.Split(req.RemoteAddr, ":")

	fmt.Println("CODE:", code, ",IP:", remoteAddr[0], ", method:", req.Method)
}

func healthz(w http.ResponseWriter, req *http.Request) {
	logger(req, http.StatusOK)

	for key, val := range req.Header {
		w.Header().Set(key, strings.Join(val, " "))
	}

	w.Header().Set("Window-Path", os.Getenv("Path"))
	
	w.Write([]byte("healthz.\n"))
}

func main() {
	http.HandleFunc("/healthz", healthz)
	
	err := http.ListenAndServe(":8888", nil)

	if err != nil {
		log.Fatal("http server err:", err)
	}
}